//package Meet;
//
//import java.sql.*;
//import java.util.Properties;
//
//public class Database {
//    private static final String URL = "jdbc:mysql://sh-cdb-l52i6pgu.sql.tencentcdb.com:29750/schoolmeeting";
//    private static final String USER = "root";
//    private static final String PASSWORD = "745698Mjt123";
//
//    static {
//        try {
//            Class.forName("com.mysql.cj.jdbc.Driver");
//            System.out.println("✅ MySQL驱动加载成功");
//        } catch (ClassNotFoundException e) {
//            System.err.println("❌ 驱动加载失败：" + e.getMessage());
//            e.printStackTrace();
//        }
//    }
//
//    public static Connection getConnection() throws SQLException {
//        Properties properties = new Properties();
//        properties.setProperty("user", USER);
//        properties.setProperty("password", PASSWORD);
//        properties.setProperty("useSSL", "false");
//        properties.setProperty("autoReconnect", "true");
//        return DriverManager.getConnection(URL, properties);
//    }
//
//    public static User getUserInfo(String account) {
//        String sql = "SELECT * FROM user WHERE account = ?";
//        try (Connection conn = getConnection();
//             PreparedStatement pstmt = conn.prepareStatement(sql)) {
//
//            pstmt.setString(1, account);
//            try (ResultSet rs = pstmt.executeQuery()) {
//                if (rs.next()) {
//                    return new User(
//                            rs.getString("Name"),
//                            rs.getString("Upassword"),
//                                rs.getString("Sex"),
//                            rs.getInt("Age"),
//                            rs.getString("ID"),
//                            rs.getString("Identity"),
//                            rs.getString("Uarea"),
//                            rs.getString("UPower"),
//                            rs.getString("Sdept")
//
//                    );
//                }
//            }
//        } catch (SQLException e) {
//            System.err.println("❌ 用户查询失败：" + e.getMessage());
//            e.printStackTrace();
//        }
//        return null;
//    }
//
//    public static boolean updateUser(User user) {
//        String sql = "UPDATE user SET Name=?, password=?, gender=?, age=?, " +
//                "campus=?, identity=?, grade=?, email=?, phone=?, " +
//                "department=?, update_time=? WHERE account=?";
//
//        try (Connection conn = getConnection();
//             PreparedStatement pstmt = conn.prepareStatement(sql)) {
//
//            pstmt.setString(1, user.getName());
//            pstmt.setString(2, user.getUpassword());
//            pstmt.setString(3, user.getSex());
//            pstmt.setInt(4, user.getAge());
//            pstmt.setString(5, user.getID());
//            pstmt.setString(6, user.getIdentity());
//            pstmt.setString(7, user.getUarea());
//            pstmt.setString(8, user.getUPower());
//            pstmt.setString(9, user.getSdept());
//
//
//            int rowsAffected = pstmt.executeUpdate();
//            return rowsAffected > 0;
//        } catch (SQLException e) {
//            System.err.println("❌ 用户信息更新失败：" + e.getMessage());
//            e.printStackTrace();
//            return false;
//        }
//    }
//}
package ExistMeets;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

class Database {
    private static final String URL = "jdbc:mysql://sh-cdb-l52i6pgu.sql.tencentcdb.com:29750/schoolmeeting";
    private static final String USER = "root";
    private static final String PASSWORD = "745698Mjt123";

    static {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            System.out.println("✅ MySQL驱动加载成功");
        } catch (ClassNotFoundException e) {
            System.err.println("❌ 驱动加载失败：" + e.getMessage());
            e.printStackTrace();
        }
    }

    public static Connection getConnection() throws SQLException {
        Properties properties = new Properties();
        properties.setProperty("user", USER);
        properties.setProperty("password", PASSWORD);
        properties.setProperty("useSSL", "false");
        properties.setProperty("autoReconnect", "true"); // 修正属性名
        return DriverManager.getConnection(URL, properties);

    }


    }
